package com.bawei.module_home.model.repository


import com.bawei.lib_common.entity.SendCommentBody
import com.bawei.lib_net.RetrofitFactory
import com.bawei.module_home.model.api.HomeApi
import com.bawei.module_home.model.entity.SimpleTypeEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn


class HomeRepository {
    val api: HomeApi
    init {
        api= RetrofitFactory.getRetrofitFactory().create(HomeApi::class.java)
    }
    /**
     * 获取视频类型信息
     */
    fun getSimpleType() = flow {
        emit(api.getSimpleType())
    }.flowOn(Dispatchers.IO)
    /**
     * 根据ChannelId获取对应视频信息
     */
    fun getSimpleVideoByChannelId(channelId: String, page: Int, pageSize: Int) = flow {
        emit(api.getSimpleVideoByChannelId(channelId, page, pageSize))
    }.flowOn(Dispatchers.IO)
    /**
     * 获取视频评论信息
     */
    fun getCommentByUserId(datatype: Int, itemid: String) = flow {
        emit(api.getCommentByUserId(datatype, itemid))
    }.flowOn(Dispatchers.IO)
    /**
     * 发送评论
     */
    fun sendComment(body: SendCommentBody) = flow {
        emit(api.sendComment(body))
    }.flowOn(Dispatchers.IO)
    /**
     * 删除评论
     */
    fun deleteComment(commentid: Int) = flow {
        emit(api.deleteComment(commentid))
    }.flowOn(Dispatchers.IO)
    /**
     * 点赞
     */
    fun agreeComment(commentid: Int) = flow {
        emit(api.agreeComment(commentid))
    }.flowOn(Dispatchers.IO)
    /**
     * 取消点赞
     */
    fun cancelAgreeComment(commentid: Int) = flow {
        emit(api.cancelAgreeComment(commentid))
    }.flowOn(Dispatchers.IO)

    fun updateAccountAmount(id: Int, nm: String) = flow {
        emit(api.updateAccountAmount(id, nm))
    }.flowOn(Dispatchers.IO)
}